package com.jic.interaction.weUM.common.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author bourne
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RestResult<T> implements Serializable {

    private static final String SUCCESS_CODE = "0";
    private static final String SUCCESS_MESSAGE = "验密成功";
    private static final String ERROR_MESSAGE = "请求失败";

    private String code;//返回代码，⻓度为8，最后4位为0时表示成功
    private String msg;
    private T data;

    public static RestResult error(String code, String message) {
        return RestResult.builder()
                .code(code)
                .msg(message)
                .build();
    }

    public static <T> RestResult<T> success(String bizNo, T data) {
        return RestResult.<T>builder()
                .code(SUCCESS_CODE)
                .data(data)
                .msg(SUCCESS_MESSAGE)
                .build();
    }

    public static boolean checkIsSuccess(RestResult restResult) {
        if (restResult != null && SUCCESS_CODE.equals(restResult.getCode())) {
            return true;
        }
        return false;
    }
}
